package com.xuecheng.teaching.controller;

import com.xuecheng.commons.model.dto.PageRequest;
import com.xuecheng.commons.model.dto.WorkDto;
import com.xuecheng.commons.model.dto.WorkQueryDto;
import com.xuecheng.commons.model.vo.ResponseResult;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.teaching.service.WorkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 作业前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
@RequestMapping("/work")
public class WorkController {

    @Autowired
    private WorkService  workService;

    /**
     * 分页条件查询课程计划作业列表
     * @param pageRequest 分页请求参数
     * @param dto WorkPageDto
     * @return vo
     */
/*    @PostMapping("/list")
    public ResponseResult findByPage(PageRequest pageRequest, @RequestBody WorkQueryDto dto){
        return workService.findByPage(pageRequest,dto);
    }*/
    @PostMapping("/list")
    public ResponseResult findByPage(PageRequest pageRequest){
        return workService.findByPage(pageRequest);
    }
    /**
     * 根据id删除
     * @param workId 作业id
     * @return null
     */
    @DeleteMapping("/{workId}")
    public ResponseResult deleteById(@PathVariable("workId") Long workId){
        return workService.deleteById(workId);
    }

    /**
     * 根据id查询作业
     * @param workId 作业id
     * @return vo
     */
    @GetMapping("/{workId}")
    public ResponseResult findById(@PathVariable("workId") Long workId){
        return workService.findById(workId);
    }

    /**
     * 新增或修改作业
     * @param dto 作业dto
     * @return null
     */
    @PostMapping
    public ResponseResult updateOrSave(@RequestBody WorkDto dto){
        return workService.updateOrSave(dto);
    }
}

